<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
// import { createRequire } from "module";
// const require = createRequire(import.meta.url);
// console.log(require, "require");

import * as echarts from "echarts";
// require('echarts/theme/macarons') // echarts theme
import("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
let chart = null

export default {
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: "chart",
        },
        width: {
            type: String,
            default: "100%",
        },
        height: {
            type: String,
            default: "300px",
        },
    },
    data() {
        return {
            // chart: null,
        };
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart();
        });
    },
    beforeDestroy() {
        if (!chart) {
            return;
        }
        chart.dispose();
        chart = null;
    },
    methods: {
        initChart() {
            chart = echarts.init(this.$el, "macarons");

            chart.setOption({
                tooltip: {
                    trigger: "item",
                    formatter: "{a} <br/>{b} : {c} ({d}%)",
                },
                legend: {
                    left: "center",
                    bottom: "10",
                    data: ["华东", "华北", "华中", "华南", "西南","西北","东北"],
                },
                series: [
                    {
                        name: "WEEKLY WRITE ARTICLES",
                        type: "pie",
                        // roseType: "radius",
                        radius: [15, 95],
                        center: ["50%", "38%"],
                        data: [
                            { value: 79, name: "华东" },
                            { value: 249, name: "华北" },
                            { value: 120, name: "华中" },
                            { value: 640, name: "华南" },
                            { value: 600, name: "西南" },
                            { value: 600, name: "西北" },
                            { value: 600, name: "东北" },
                        ],
                        animationEasing: "cubicInOut",
                        animationDuration: 2600,
                    },
                ],
            });
        },
    },
};
</script>